<?php use_helper('Date') ?>
<?php use_helper('jQuery') ?>

<div id="sf_admin_container">
  <h1><?php echo $ticket->Project->name.' :: <span id="title-ticket-closed">'.($ticket->is_closed ? '[Закрыт] ':'').'</span>'.$ticket->title ?></h1>
  <p style="text-transform: lowercase;">
    <?php include_partial('indicator',array('ticket'=>$ticket)) ?> (<?php echo $ticket->getIndicatorAlt($sf_user->getGuardUser()->Profile->getRawValue()) ?>)
  </p>
  <p>
    создан <?php echo format_date($ticket->getCreatedAt(), "f") ?>, изменен <?php echo format_date($ticket->getUpdatedAt(), "f") ?>
  </p>
  <p>
    <?php if ($ticket->VisibleToUsers->count()): ?>
      Виден пользователям: 
      <?php foreach ($ticket->VisibleToUsers as $i=>$user): ?>
        <?php echo $user->User->username ?><?php echo $i<$ticket->VisibleToUsers->count()-1 ? ',':'.' ?> 
      <?php endforeach ?>
      
    <?php else: ?>
      Тикет никому не виден (полностью скрыт)
    <?php endif ?>
  </p>
  <p>
    Ответственный: <?php echo $ticket->CurrentUser->User->username ?>
    <?php if ($ticket->CurrentUser->id == $sf_user->getGuardUser()->id): ?>
      (это же я!)
    <?php endif ?>
  </p>
  
  <p>
    <?php include_partial('open_close_button',array('ticket'=>$ticket)) ?>
  </p>
  
  
  
  <?php if (count($messages)): ?>
  <h2>Ответы и действия</h2>
  <table width="100%" cellspacing="0" cellpadding="10" class="messages">
  <?php foreach ($messages as $i=>$message): ?>
    <tr class="ticket-message<?php if ($i % 2 ==1) echo ' odd' ?>" id="message-<?php echo $message->id ?>">
      <td width="1%">
        <h3><?php echo $message->User->User->username ?></h3>
        <img src="<?php echo $message->User->getPreviewFotoWebpath() ?>" alt="<?php echo $message->User->User->username ?>">
        <p><?php echo $message->User->fullname ?></p>
      </td>
      <td>
        <a href="#message-<?php echo $message->id ?>" class="message-number">#<?php echo sprintf('%04d',$message->id) ?></a>
        <span class="ticket-message-date"><?php echo format_date($message->getUpdatedAt(), "f") ?></span>
        
        <p>
          <?php if ($message->VisibleToUsers->count()): ?>
            Видно пользователям: 
            <?php foreach ($message->VisibleToUsers as $i=>$user): ?>
              <?php echo $user->User->username ?><?php echo $i<$message->VisibleToUsers->count()-1 ? ',':'.' ?> 
            <?php endforeach ?>
            
          <?php else: ?>
            Сообщение никому не видно (полностью скрыто)
          <?php endif ?>
        </p>
        
        <p>
          <?php echo nl2br(trim($message->text)) ?>
        </p>
      </td>
    </tr>
  <?php endforeach ?>
  </table>
  <?php endif ?>
  
  
  
  
  
  <h2>Написать ответ</h2>
  <form method="post" action="<?php echo url_for('@message_new') ?>" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
  <?php echo $form->renderHiddenFields() ?>
  <table class="table1">
    <tr>
      <td><?php echo $form['text']->renderLabel() ?></td>
      <td>
        <?php echo $form['text']->renderError() ?>
        <?php echo $form['text']->render() ?>
      </td>
    </tr>
    <?php if (isset($form['visible_to_users_list'])): ?>
    <tr>
      <td><?php echo $form['visible_to_users_list']->renderLabel() ?></td>
      <td>
        <?php echo $form['visible_to_users_list']->renderError() ?>
        <?php echo $form['visible_to_users_list']->render() ?>
      </td>
    </tr>
    <?php endif ?>
    <?php if (isset($form['current_user_id'])): ?>
    <tr>
      <td><?php echo $form['current_user_id']->renderLabel() ?></td>
      <td>
        <?php echo $form['current_user_id']->renderError() ?>
        <?php echo $form['current_user_id']->render() ?>
      </td>
    </tr>
    <?php endif ?>
    <tr>
      <td colspan="2">
        <input type="submit" value="Отправить">
      </td>
    </tr>
  </table>
  </form>
  
  <p>
    <?php include_partial('open_close_button',array('ticket'=>$ticket)) ?>
  </p>
  
  
  
</div>

